<?php
class RSITE_Plugin_Acl extends Zend_Controller_Plugin_Abstract{
	protected $_auth = null;
	protected $_acl = null;
	
	public function __construct(Zend_Auth $auth, Zend_Acl $acl){
		$this->_auth = $auth;
		$this->_acl = $acl;
	}
	
	public function preDispatch(Zend_Controller_Request_Abstract $request){
		if($this->_auth->hasIdentity())
			$role = 'usuario';	
		else 
			$role = 'visitante';
			
		$resource = 'paginas';
		if(!$this->_acl->has($resource))
		{
			$resource = null;
		}
		//verificar acesso acl
		if(!$this->_acl->isAllowed($role,$resource))
		{
			if($this->_auth->hasIdentity())
			{
				$request->setModuleName('admin');
				$request->setActionName('index');
				$request->setControllerName('index');
			}
			else{
				$request->setModuleName('default');
				$request->setActionName('index');
				$request->setControllerName('index');
			}
		}
	}
}